<?php
namespace app\admin\model;
use \think\Db;
class Platform extends BaseModel
{
    protected $table = 'cz_with';
    protected $rule = [
        'uid'  =>  '',
    ];
    protected $msg = [
        'uid'  =>  '',
    ];
    protected $return = array();
    /**
     * 公告列表
     * @author wxy
     * @date   2018-08-03
     * inquiry 调查/查询
     */
    public function getList(){
        $res = $this->alias('w')
                ->join('users u','u.user_id = w.user_id','left')
                ->field('w.*,u.user_name')
            ->paginate(10);
        return $res;
    }


    /**
     * 获取公告一条数据
     * @author wxy
     * @date   2018-08-03
     */
    public function getById(){
        $id = input("id");
        $res = $this->alias("w")->join("users u ","w.user_id=u.user_id")->field("w.*,u.user_name")->where(['with_id'=>$id])->find();
        return $res;
    }
    /**
     * 公告修改
     * @author wxy
     * @date   2018-08-03
     */
    public function about_edit(){
        $data = input('post.');
        $with = $this->where('with_id',$data['id'])->find();
        if($data['message_type'] == 1)
        {
            $with_update = $this->where('with_id',$data['id'])->update(['status'=>1]);
           
            // 减少用户余额        
        }else{
            $with_update = $this->where('with_id',$data['id'])->update(['status'=>2,'content'=>$data['message']]);
            $user = Db::name('users')->where('user_id',$with['user_id'])->setInc('money',$with['with_money']);
        }
        if($with_update){
            return $status = [
                'code' => 1,
                'msg' => '操作成功'
            ];
        }else{
            return $status = [
                'code' => 0,
                'msg' => '操作失败'
            ];
        }
    }
    //删除公告
    public function del($id){
        $res = $this->where("with_id = ".$id)->delete();
        if($res){
            $this->return ['status'] = 1;
            $this->return ['msg'] = "删除成功";
        }else{
            $this->return ['status'] = 0;
            $this->return ['msg'] = "删除失败";
        }
        return $this->return;
    }
}
